package com.hbl.cgs.cgsagent;

import com.fasterxml.jackson.databind.JsonNode;

import java.io.File;
import java.util.*;

public class Utils {
    private Utils() {}

    public static Map<String, String> jsonNode2Map(JsonNode node) {
        Map<String, String> result = new HashMap<>();
        Iterator<String> fieldNames = node.fieldNames();
        while (fieldNames.hasNext()) {
            String fieldName = fieldNames.next();
            String value = node.get(fieldName).isValueNode() ? node.get(fieldName).asText() :
                    node.get(fieldName).toString();
            result.put(fieldName, value);
        }
        return result;
    }

    public static List<String> getPluginsConfigPath() {
        List<String> pluginConfigs = new ArrayList<>();
        String bashPath = "config/pluginconfig";
        File file = new File(bashPath);
        String[] list = file.list();
        for (String pluginsConfig : list) {
            String configPath = bashPath + pluginsConfig;
            pluginConfigs.add(configPath);
        }
        return pluginConfigs;
    }
}
